#export PATH=/usr/local/kaldi/tools/openfst-1.6.7/bin:$PATH  # 写在node54的.bashrc中了
#export PATH=/home/work_nfs15/asr_data/ckpt/xlgeng/word_seg/openfst-1.6.7/bin:$PATH
export PATH=/home/work_nfs15/asr_data/ckpt/xlgeng/word_seg/fstbin:$PATH
export PATH=/home/work_nfs15/asr_data/ckpt/xlgeng/word_seg/lmbin:$PATH
export PATH=/home/work_nfs15/asr_data/ckpt/xlgeng/word_seg/srilm/path/bin:$PATH
export PATH=/home/work_nfs15/asr_data/ckpt/xlgeng/word_seg/srilm/bin:$PATH
export PATH=/home/work_nfs15/asr_data/ckpt/xlgeng/word_seg/srilm/lm/bin/i686-m64:$PATH
export PATH=/usr/local/openfst-1.6.7/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/openfst-1.6.7/lib:$LD_LIBRARY_PATH
export PATH=/home/work_nfs5_ssd/pcguo/code/kaldi/src/fstbin:$PATH
export PATH=/home/work_nfs5_ssd/pcguo/code/kaldi/src/lmbin:$PATH

# 首先就是让tools中的文件都有可执行权限
chmod 755 ./tools/fst/*

thres=0.0000000000001 #表示在训练语言模型时，如果一个n-gram（比如一个特定的词组）在训练数据中的频率低于这个阈值，就将其剪掉， 0.0001输入剪切力度较弱的值 ，设为0是不剪切
unit_path=/home/work_nfs15/asr_data/ckpt/asr_online_system/lang_char_bpe/tokens.txt
world_list_path=/home/work_nfs15/asr_data/ckpt/xlgeng/word_seg/word_95w.list    # 只有纯粹的词，没虚词。 只要每行split之后的第一个是就行
bpe_model_path=/home/work_nfs15/asr_data/ckpt/asr_online_system/lang_char_bpe/bpe.model

input_text_path=/home/node54_tmpdata/xlgeng/code/gxl_ai_utils/eggs/cats_and_dogs/ngram_task/data_handler/gxl_data_zoo/asr_poi_xian/final_data.list
output_dir=./gxl_arpa_zoo/asr_poi_xian/thres_$thres
mkdir -p $output_dir



mkdir -p ${output_dir}/local/dict
output_lexison_path=${output_dir}/local/dict/lexicon.txt
cp $unit_path ${output_dir}/local/dict/units.txt
python tools/fst/prepare_dict.py $unit_path $world_list_path $output_lexison_path $bpe_model_path
lm=${output_dir}/local/lm
mkdir -p $lm
# input_text_path是分过词的文本文件。
cp $input_text_path $lm/text
# 训练ngram模型只需要文本和词典即可
bash local/aishell_train_lms.sh ${output_dir}/local/lm/text ${output_dir}/local/dict/lexicon.txt ${output_dir}/local/lm 3 $thres
# 构图开始
# 第一个目录是输入，需要含有unit.txt和lexicon.txt。 第二个目录是tmp。第三个目录是输出目录。
bash tools/fst/compile_lexicon_token_fst.sh \
    ${output_dir}/local/dict ${output_dir}/local/tmp ${output_dir}/local/lang
bash tools/fst/make_tlg.sh ${output_dir}/local/lm ${output_dir}/local/lang ${output_dir}/lang_test || exit 1;

# 得到在lm ：lm.arpa  ;;   lang_test, lang_test/HLG.fst文件